A set of classes for using WASTE with the Think Class Libraries
by Dan Crevier
Signficant contributions by Mark Alldritt
Introduction
This is a set of classes I've written to use Marco Piovanelli's text edit replacement WASTE with the Think Class Libraries. It only works with versions 2.0.3 or later of TCL. It has currently been tested with WASTE 1.0a4 - 1.0.
I wanted to use WASTE in one of my applications mainly for the ability to use more than 32K of text, and to use inline input for Japanese. The classes are not well tested at this point, and probably contain many bugs. I am releasing these classes as public domain, so you are free to use them as you see fit. Remember to give Marco Piovanelli credit if you use WASTE, and you can give me some credit if you feel like it. If you use these classes, I'd be very interested in any bug reports (especially if they include fixes) and any improvements anyone makes. I'd like to thank Marco Piovanelli both for making WASTE available and for his help in figuring out how to get it to work with the class libraries.
If you have used a previous version of the classes, see the what's new section.
There are 5 classes included. They are:
CWASTEText - a subclass of CAbstractText which is much like
CStyleText
CWASTEDlgText - a subclass of CWASTEText which is a bit like
CDialogText, but without all of the validation features. It
has a border, broadcasts changes when the text changes,
and passes return, enter and escape to the supervisor.
CTSMSwitchboard - a subclass of CSwitchboard which deals
with Text Service Manager events.
CWASTEEditTask - a class for handling undo with CWASTEText
CWASTEStyleTask - a class for handling undo'ing style changes with CWASTEText
I also made some slight modifications to the WASTE header files. Hopefully Marco will be able to include these in future versions of WASTE.
I've also included a slightly modified version of TinyEdit, called WASTEEdit, which uses WASTE as a simple example program.
You are free to use these classes in any of your products (freeware, shareware, or commercial).
Adding WASTE Support
If you wish to use these classes in your application, you need to add the following to your application class:
Near the top:
#include "WASTE.h"
#ifndef __SCRIPT__
#include <Script.h>
#endif
#include "CTSMSwitchboard.h"
static Boolean TSMAvailable(void);
short gUsingTSM = false;
In the constructor:
gUsingTSM = TSMAvailable();
if (gUsingTSM) gUsingTSM = (InitTSMAwareApplication()==noErr);
See WASTEEdit for an example. Most of this stuff is to provide inline input. Even if you don't use Japanese on your system, I recommend leaving the support there for those that do have inline input.
You need to add CTSMSwitchboard.cpp, CWASTEText.cpp, CWASTEDlgText.cpp, CWASTEEditText.cpp, CWASTEStyleText.cpp and WASTE.o to your project.
CWASTEText
CWASTEText is a subclass of CAbstractText, and is very similar to CStyleText. In addition, I have added the following functions:
StopInlineSession() - Stops the current inline input session
and validates the text.
InsertWithStyle() - Lets you insert some text and it's
corresponding StScrpHandle information all in one step.
Clear() - clears the text in the class without any excess
highlighting.
CopyRangeWithStyle() - gets the text and styles for a range
of text all in one step.
SetOutlineHighlighting() - turns outline highlighting on or off. Returns old
setting.
SetFontNumberAll() - sets the font of all of the text.
SetFontNameAll() - sets the font of all of the text.
SetFontSizeAll() - sets the size of all of the text.
SetFontStyleAll() - applies a style to all of the text
TempSelectAll() - temporarily selects all of the text while deactivating the text
and turning off outline hilighting so that the selection won't show up. It can
be restored by Restore selection. This is useful when you want to apply
something to all of the text without seeing all of the text flash. It is a
protected routine used by Clear() and the Set*All() functions.
There are some problems with CWASTEText. A lot of the functions haven't been tested well or at all. Also, I should add some functions for easy color support. TCL isn't good at supporting text without fixed height lines. SetWholeLines(true) doesn't work well. I set the scrolling steps to 12 vertically and 4 horizontally fow when it's in a scroll pane. Something more intelligent could probably be done.
CWASTEDlgText
CWASTEDlgText was made to provide some of the funcitonality of CDialogText. A dialogTextChanged message is broadcast when the text is changed. This wasn't easy for text being entered with inline input, but I think I have it working with a WEPostUpdate routine. It may be broadcasting the message more often than it needs to, but that's ok with me.
It also has a border, just like CDialogText, and passes tab, return, enter, and escape to the supervisor instead of typing them.
I added the GetTextString() method to get the text into a Str255.
CTSMSwitchboard
This is a subclass of CSwitchboard which handles Text Service Manager events.
CWASTEEditTask & CWASTEStyleTask
These two classes were written by Mark Alldritt. They are created by CWASTEText to take care of undoing actions and you don't need to use them directly.
WASTEEdit
WASTEEdit is a slightly modified version of TinyEdit to get it to work with WASTE. I tried to do the minimum modifications necessary to get it to work, so I haven't added any functionality. With a little work, I think a nice application could be made out of it. Right now, it's almost 10 times as big as WASTE Demo, and doesn't do quite as much. It would be really great if someone wanted to add all the scripting support to it, so we would have a nice replacement for the Scriptable Text Editor.
What's new
• Version 1.1
Unfortunately I haven't kept track of the changes made in the classes very well. There were many changes, most of them for improved error checking. Marco Piovanelli and Mark Alldritt made many contributions, and I made some changes myself. Also, I have used the classes with my port of WASTE to C. In the file CWASTEText.cpp, you need to define/undefine CWASTE depending on whether or not you are using the C version of WASTE.
Let me know if you have any bug fixes or problems.